//
//  RBLogisticsListCell.m
//  zhongzhenglu
//
//  Created by 马军凯 on 2023/5/9.
//

#import "RBLogisticsListCell.h"

@interface RBLogisticsListCell ()
//日期
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
//时间
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;

@property (weak, nonatomic) IBOutlet UIView *topLineView;

@property (weak, nonatomic) IBOutlet UIView *bottomLineView;

@property (weak, nonatomic) IBOutlet UIView *circleView;

@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *dashedLineView;

@end

@implementation RBLogisticsListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //
        CAShapeLayer *layer = CAShapeLayer.layer;
        [layer setBounds:self.dashedLineView.bounds];
        [layer setPosition:CGPointMake(0.5, self.dashedLineView.height / 2)];
        [layer setLineWidth:1];
        [layer setLineJoin:kCALineJoinRound];
        [layer setFillColor:[UIColor clearColor].CGColor];
        [layer setStrokeColor:[UIColor LC_hex:@"#518CFF"].CGColor];
        [layer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:1], nil]];
        
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 0.5, 0);
        CGPathAddLineToPoint(path, NULL, 0.5, self.dashedLineView.height);
        [layer setPath:path];
        CGPathRelease(path);
        [self.dashedLineView.layer addSublayer:layer];
    });
}
//赋值
- (void)setModel:(RBLogisticsKuaidiDataModel *)model {
    _model = model;
    //日期
    NSArray *dateArray = [model.time componentsSeparatedByString:@" "];
    //日期
    NSString *date = dateArray.firstObject;
    NSString *a = [date substringWithRange:NSMakeRange(date.length - 5, 5)];
    self.dateLabel.text = a;
    //时间
    NSString *time = dateArray.lastObject;
    self.timeLabel.text = [time substringToIndex:5];
    //状态
    self.statusLabel.text = model.status;
    //
    self.titleLabel.text = model.context;
    //
    if (model.index == 0) {
        self.dashedLineView.hidden = NO;
        self.topLineView.hidden = YES;
        self.bottomLineView.hidden = NO;
        self.circleView.backgroundColor = [UIColor LC_hex:@"#518CFF"];
        self.timeLabel.textColor = self.dateLabel.textColor = self.statusLabel.textColor = self.titleLabel.textColor = [UIColor LC_hex:@"#202224"];
        self.dateLabel.font = [UIFont systemFontOfSize:14];
    } else {
        self.dashedLineView.hidden = YES;
        self.dateLabel.font = [UIFont systemFontOfSize:10];
        self.topLineView.hidden = NO;
        self.bottomLineView.hidden = NO;
        self.circleView.backgroundColor = [UIColor LC_hex:@"#CDCDCD"];
        self.timeLabel.textColor = self.dateLabel.textColor = self.statusLabel.textColor = self.titleLabel.textColor = [UIColor LC_hex:@"#8D8D8D"];
        if (model.isLast == YES) {
            self.bottomLineView.hidden = YES;
        }
    }
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
